'''
         vR
[-4, -1, 0, 3, 10]
         ^L

L: nums 中最小的值
R: nums 中最大的值

result
             v
[0, 0, 0, 0, 0]
'''

'''
            vr
[-5, -2, 1, 3, 9]
 ^l
'''
# 252  2 + 5 + 2 = 9
# [xx, xxx, xxx, xx, xxx, xxx, xxxx, xx]

# 找到一个整数列表里的所有偶数的数量

# 判断 n 的数位和是否是一个奇数
def sum_is_odd(n: int) -> bool:
    str_n = str(n)
    digits = []

    for c in str_n:
        digits.append(int(c))

    return sum(digits) % 2 != 0



def count_even(nums: list[int]) -> int:
    result = 0

    for n in nums:
        if n % 2 == 0 and sum_is_odd(n):
            result += 1

    return result

def sorted_squares (nums):

    result = [0] * len(nums) 

    l = 0
    r = len(nums) - 1
    p = len(result) - 1
    
    for i in range(len(result)-1, -1, -1):
        powL = nums[l] * nums[l]
        powR = nums[r] * nums[r]
    
        if powL >= powR:
            result[i] = powL
            l += 1
        
        else:
            result[i] = powR
            r -= 1
    
    return result

print(sorted_squares([-5, -2, 1, 3, 9]))
